const app = getApp();
const req = require("../../utils/http.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:'',
    page: 1,
    size: 10,
    newList:[]
  },

  newGiftList(page, size){
    let t = this 
    let params = {}
    req.wxReq(`/coupon/wxActivityProduct/selectNewGift/${page}/${size}`,'POST',params).then(res=>{
      if (res.data.code == 200) {
        let list = res.data.result.records
        let newList = t.data.newList.concat(list)
        t.setData({
          newList,
          total: res.data.result.total
        })
      } else {
        wx.showToast({
          title: res.data.message,
          icon: 'none',
          duration: 1500
        })
      }
    })
    
  },
 
  priceClik(e){
      console.log(e)
    let objectType= e.currentTarget.dataset.objectType
    let setType = '' //0免费领 1购买
    if (objectType==0){
      setType='0'
    }else{
      setType = '1'
    }
    let id = e.currentTarget.dataset.id
    let type = '2'
      wx.navigateTo({
        url: '../product/index?productId=' + id + '&setType=' + setType + '&type=' + type
      })
    
  },

  onLoad: function (options) {
    let t = this
    t.setData({
      userInfo: wx.getStorageSync("isUifo")
    })
    
    let page = t.data.page;
    let size = t.data.size;
    let name = options.name
    t.newGiftList(page, size)
    wx.setNavigationBarTitle({
      title: name,
    })
  },

  


  onReachBottom: function () {
    let t = this
    wx.showLoading({
      title: '玩命加载...',
    })
    var page = t.data.page + 1;
    t.setData({
      page: page
    })
    if (page > Math.ceil(t.data.total / t.data.size)) {
      wx.showToast({
        title: '到底了！！！',
        icon: 'none'
      })
      return;
    };
    t.newGiftList(page, t.data.size);
    wx.hideLoading()
  },


})